#include "SocketEndPoint.h"
#include <sstream>

SocketEndPoint::SocketEndPoint()
{
    this->ipAddress = IpAddress::ANY;
    this->port = PORT_UNSPECIFIED;
    createEndPointString();
}

SocketEndPoint::SocketEndPoint(const IpAddress & ipAddress, int port)
{
    this->ipAddress = ipAddress;
    this->port = port;
    createEndPointString();
}

void SocketEndPoint::createEndPointString()
{
    stringstream ss;   
    ss << ipAddress.toString() << ":" << port;   
    endPointString = ss.str();
}

const IpAddress & SocketEndPoint::getIpAddress() const
{
    return ipAddress;
}

int SocketEndPoint::getPort() const
{
    return port;
}

void SocketEndPoint::setIpAddress(const IpAddress & ipAddress)
{
    this->ipAddress = ipAddress;
    createEndPointString();
}

void SocketEndPoint::setPort(int port)
{
    this->port = port;
    createEndPointString();
}

const string & SocketEndPoint::toString() const
{
    return endPointString;
}


